package com.caul.demo.hadoop.mapreduce.attention;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created by BlueDream on 2018-04-08.
 */
public class BothAttentionMapper extends Mapper<LongWritable, Text, BothAttentKey, IntWritable> {

  private static BothAttentKey textKey = new BothAttentKey();
  private static IntWritable valueKey = new IntWritable(1);

  @Override
  protected void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {
    String[] users = value.toString().split(":");
    for (String attenter : users[1].split(",")) {
      textKey.set(users[0], attenter);
      context.write(textKey, valueKey);
    }
  }
}
